package org.westos.controller;

import org.springframework.web.bind.annotation.RestController;
import org.westos.pojo.ChuFang;
import org.westos.pojo.ChuFangYao;
import org.westos.pojo.ChufangDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.westos.pojo.ShowChu;
import org.westos.service.ChufangService;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TestController {
    @Autowired
    private ChufangService chufangService;

    @GetMapping("hello")
    public String getMsg(Model model){
        ChuFangYao yao1 = new ChuFangYao(1, 2, 3, "每天三次，每次一片", "孕妇、儿童禁用", "");
        ChuFangYao yao2 = new ChuFangYao(1, 3, 2, "每次一片", "儿童禁用", "");
        ArrayList<ChuFangYao> yaos = new ArrayList<>();
        //添加药品
        yaos.add(yao1);
        yaos.add(yao2);
        ChuFang chuFang1 = new ChuFang(null, null, 2, "张三", 18, 50, "酒精过敏", "患有XX病", "长安区大学城", "18891943503", null, "王大夫", "张大夫", "李大夫", "陈大夫", 0);

        Integer integer = chufangService.addChu(new ChufangDto(chuFang1, yaos));
        return integer.toString();
    }
    @GetMapping("hello2")
    public String getMsg2(Model model){
        ChuFangYao yao1 = new ChuFangYao(2, 2, 3, "每天三次，每次一片", "孕妇、儿童禁用", "");
        ChuFangYao yao2 = new ChuFangYao(2, 3, 2, "每次一片", "儿童禁用", "");
        ArrayList<ChuFangYao> yaos = new ArrayList<>();
        //添加药品
        yaos.add(yao1);
        yaos.add(yao2);
        ChuFang chuFang1 = new ChuFang(null, null, 2, "张三", 18, 50, "酒精过敏", "患有XX病", "长安区大学城", "18891943503", null, "王大夫", "张大夫", "李大夫", "陈大夫", 0);

        Integer integer = chufangService.addChu(new ChufangDto(chuFang1, yaos));
        return integer.toString();
    }
    @GetMapping("queryByDoc")
    public String queryByDoc(Model model){
        List<ShowChu> chus = chufangService.queryByDoc("王大夫");
        return chus.toString();
    }

}
